package com.monlyu.action.firm;

import com.monlyu.action.BaseAction;
import com.monlyu.annotation.ActionAnno;
import com.monlyu.bo.FirmBo;
import com.monlyu.bo.RoleBo;
import com.monlyu.vo.Firm;

/********************************************************************************
 * 
 * <b>功能描述☞</b><br>
 * 
 * <b>开发公司☞</b>重庆唯尼科技有限公司<br>
 * <b>版权☞</b>本文件归重庆唯尼科技有限公司所有<br>
 * <b>项目名☞</b>NewsSys<br>
 * <b>文件路径☞</b>com.monlyu.action.firm.EditFirmAction.java<br>
 * <b>开发日期☞</b>2010-2-10 <br>
 * 
 * @author zengjun
 * @since JDK 5
 * @version 1.0.8
 * 
 ********************************************************************************/
public class EditFirmAction extends BaseAction {

	private Firm firm;

	private FirmBo firmBo;

	private RoleBo roleBo;

	public void setRoleBo(RoleBo roleBo) {
		this.roleBo = roleBo;
	}

	public Firm getFirm() {
		return firm;
	}

	public void setFirm(Firm firm) {
		this.firm = firm;
	}

	public void setFirmBo(FirmBo firmBo) {
		this.firmBo = firmBo;
	}

	@ActionAnno(readOnly = false)
	public String execute() {
		if(!roleBo.checkPermission("FIRM_MANAGE")){
			return ajax("e无权访问系统资源：FIRM_MANAGE");
		}
		String error = null;
		if (firm != null && firm.getId() != null) {
			error = firmBo.updateFirm(firm);
		} else {
			error = firmBo.insertFirm(firm);
		}
		if (error != null) {
			return ajax("e" + error);
		}
		return ajax(firm.getId());
	}

	public String toEdit() {
		roleBo.checkPermission("FIRM_MANAGE");
		if (firm != null && firm.getId() != null) {
			firmBo.load(firm);
		}
		return view("firmForm.jsp");
	}

	@ActionAnno(readOnly = false)
	public String delete() {
		roleBo.checkPermission("FIRM_MANAGE");
		firmBo.delete(Firm.class, firm.getId());
		return ajax();
	}
}
